package utils;

import com.mysql.jdbc.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class XBUtils {


    /**
     * 根据cookieName获取Request请求中的cookie数组里面的指定Cookie
     * @param req
     * @param cookieName
     * @return
     */
    public static Cookie getCookie(HttpServletRequest req,String cookieName){
        if(req.getCookies() != null && !StringUtils.isNullOrEmpty(cookieName)){
            for(Cookie cookie : req.getCookies()){
                if(cookie.getName().equals(cookieName)){
                    return cookie;
                }
            }
        }
        return null;
    }
}
